
//
// Copyright 2009 Arne Halvorsen (arne.halvorsen@gmail.com)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

// Project page: http://code.google.com/p/mf4j/

//
// 091116 - aha42 - Created.
// 091121 - aha42 - Added project page link (google code) to header comment.
//

package org.aha.mf4j;

/**
 * <p>
 *   Utility methods for use when working with Flickr photo data.
 * </p>
 * @author Arne Halvorsen (aha42)
 */
public final class Photos 
{
  private Photos(){} // Utility pattern dictates private constructor.
  
  /**
   * <p>
   *   Check if single character
   *   {@code String} specify valid picture size.
   * </p>
   * @param s {@code String} to check.
   * @throws IllegalArgumentException If {@code s} does not specify legal size.
   */
  public static void checkSize(String s)
  {
    if (s==null)
    {
      throw new NullPointerException("s");
    }
    
    int n=s.length();
    if (n==0)
    {
      throw new IllegalArgumentException("s is the empty String");
    }
    if (n>1)
    {
      throw new IllegalArgumentException("s.length>1 : "+n);
    }
    
    checkSize(s.charAt(0));
  }
  
  /**
   * <p>
   *   Check if character specify valid picture size.
   * </p>
   * @param c Character to check.
   * @throws IllegalArgumentException If {@code c} does not specify legal size.
   */
  public static void checkSize(char c)
  {
    switch (c)
    {
      case 'm' :
      case 's' :
      case 't' :
      case 'b' : return;
      
      default : throw new IllegalArgumentException(
                  "does not specify valid size: "+c);
    }
  }
  
  /**
   * <p>
   *   Checks if given
   *   {@code String} specify valid format for a Flickr image.
   * </p>
   * @param f {@link String} to check.
   * @throws IllegalArgumentException If {@code f} does not specify valid 
   *         format.
   */
  public static void checkPhotoFormat(String f)
  {
    if (f==null)
    {
      throw new NullPointerException("f");
    }
    
    if (f.equals("jpg")) return;
    if (f.equals("png")) return;
    if (f.equals("gif")) return;
    
    throw new IllegalArgumentException("uknown image format : "+f);
  }
  
}
